%% Functions to plot the ratio of hat-nu and study se by group

function fig = plot_nu_se_ratio(EB_est_nu, rep_base_se2, rep_val_se2, yscale, xtick)

    % Combine rep_base_se2 and rep_val_se2 to form a N x (J+1) matrix
    mat = [rep_base_se2, rep_val_se2];
    % Convert the variances to std errors
    mat = sqrt(mat);
    
    % Compute the row averages
    row_avg = mean(mat, 2);
    
    % Compute the ratios
    ratios = sqrt(EB_est_nu) ./ row_avg;
    [sorted_ratios, ~] = sort(ratios);
    
    % Generate the plot
    fig = figure;
    set(fig, 'Units', 'inches', 'Position', [1 1 5.833 4.373]);
    plot(1:length(ratios), sorted_ratios, 'LineWidth', 2.5);
    hold on;
    yline(1, '--', 'LineWidth', 1.5); % Reference dashed line at y = 1
    ylim(yscale);

    xticks(xtick);
    xlim([xtick(1), xtick(end)]);
    xlabel('');
    ylabel('');
    title('');
    set(gca, 'FontSize', 18);
    hold off;

end